package com.mida.bms.report.controller;

import com.mida.bms.report.entity.DocStructTemplateInfo;
import com.mida.bms.report.service.DocStructParagraphService;
import com.mida.bms.report.vo.DocStructRequestVo;
import com.mida.bms.report.vo.PageResultVo;
import com.mida.bms.report.vo.TemplateJson;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import static com.mida.tool.common.result.BaseResult.buildListSuccess;

/**
 * @author ：wang xiao le
 * @description：TODO 结构化模板报告
 * @date ：2021/4/6 11:45
 */
@RestController
@RequestMapping("/docStructTemplate")
@CrossOrigin
@Slf4j
public class DocStructTemplateController {
    @Autowired
    private DocStructParagraphService docStructParagraphService;

    /**
     * 1、保存结构化模板
     *
     * @param docStructRequestVo 结构化模板vo
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public ActionResult add(@RequestBody DocStructRequestVo docStructRequestVo) throws Exception {
        return docStructParagraphService.add(docStructRequestVo);
    }


    /**
     * 2.获取结构化模板回显json
     *
     * @param stTemplateInfoSoid 结构化模板基本信息soid
     * @return
     */
    @GetMapping("/getTemplate")
    @ResponseBody
    public ListResult<DocStructRequestVo> getTemplate(@RequestParam("stTemplateInfoSoid") Long stTemplateInfoSoid) {
        ListResult<DocStructRequestVo> result = new ListResult<>();
        try {
            result = docStructParagraphService.getTemplate(stTemplateInfoSoid);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.BAD_REQUEST.value());
            result.setMessage("获取模板失败");
            return result;
        }
        return result;
    }

    /**
     * 3.1 获取报告模板缩略图
     *
     * @param stTemplateInfoSoid
     * @return
     */
    @GetMapping("/getTemplatePic")
    @ResponseBody
    public ListResult<DocStructRequestVo> getTemplatePic(@RequestParam("stTemplateInfoSoid") Long stTemplateInfoSoid) {

        ListResult<DocStructRequestVo> result = new ListResult<>();
        try {
            return docStructParagraphService.getTemplatePic(stTemplateInfoSoid);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.BAD_REQUEST.value());
            result.setMessage("获取模板缩略图失败");
            return result;
        }
    }

}
